/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.chrfra.backing;

import edu.chl.chrfra.controller.ProductJpaCtrl;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.transaction.UserTransaction;

@ManagedBean
@ApplicationScoped
public class PersistenceUtilityBean {

    @PersistenceUnit(unitName = "jsf_pu")
    private EntityManagerFactory emf;
    @Resource
    private UserTransaction utx;
    
    private ProductJpaCtrl jpaCtrl;

    /** Creates a new instance of PeristenceUtilityBean */
    public PersistenceUtilityBean() {
    }

    public ProductJpaCtrl getJpaCtrl() {
        if (this.jpaCtrl != null) {
            return this.jpaCtrl;
        } else {
            this.jpaCtrl = new ProductJpaCtrl(utx, emf);
            return this.jpaCtrl;
        }
    }

    public EntityManagerFactory getEmf() {
        return emf;
    }

    public void setEmf(EntityManagerFactory emf) {
        this.emf = emf;
    }

    public UserTransaction getUtx() {
        return utx;
    }

    public void setUtx(UserTransaction utx) {
        this.utx = utx;
    }
}
